<template>
  {{ info }}
  <div class="main">
    <div>
      <ElCard>
        <template #header>
          <div class="font-none">用户登录</div>
        </template>
        <div>
          <ElForm>
            <ElFormItem prop="text">
              <ElInput v-model="user.username" placeholder="登录名" />
            </ElFormItem>

            <ElFormItem prop="password">
              <ElInput v-model="user.password" :show-password="true" placeholder="密码" />
            </ElFormItem>

            <ElFormItem>
              <ElButton type="primary" @click="login">登录</ElButton>
              <div @click="toReg" class="font-reg font-none"> 没有账号?那就注册一个吧 </div>
            </ElFormItem>
          </ElForm>
        </div>
      </ElCard>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { ElCard, ElForm, ElFormItem, ElInput, ElButton } from 'element-plus'
import ApiService from '../../api/ApiServer'
import { useRouter } from 'vue-router'

// #region 页面内路由跳转
const router = useRouter()

function toReg() {
  router.push('/reg')
}
// #endregion

// #region 登录
const info = ref('')

const user = ref({
  username: '',
  password: '',
})

const login = () => {
  ApiService.post('/auth', user.value, (data: any) => {
    info.value = data
  })
}

// #endregion
</script>
<style lang="scss" scoped>
.main {
  width: 95vw;
  height: 95vh;
  display: flex;
  justify-content: center;
  align-items: center;
  > div {
    transform: translateY(-10vh);
    min-width: 25vw;
  }
}
.font-reg {
  font-size: 10px;
  float: right;
  margin-top: 1.1rem;
  margin-left: 11rem;
  cursor: pointer;
  &:hover {
    color: #1890ff;
  }
}
.font-none {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
</style>
